package Org.lanqiao.team.view;

import Org.lanqiao.team.domain.Programmer;
import Org.lanqiao.team.service.NameListService;
import Org.lanqiao.team.service.TeamException;
import Org.lanqiao.team.service.TeamService;

import java.util.Scanner;

import static Org.lanqiao.team.view.TSUtility.*;

public class TeamView {

    private NameListService listSvc= new NameListService();
    private TeamService teamSvc= new TeamService();

    /**• 说明：
      listSvc 和 teamSvc 属性：供类中的方法使用
      enterMainMenu ()方法：主界面显示及控制方法。
      以下方法仅供 enterMainMenu()方法调用：
      listAllEmployees ()方法：以表格形式列出公司所有成员
      getTeam()方法：显示团队成员列表操作
      addMember ()方法：实现添加成员操作
      deleteMember ()方法：实现删除成员操作*/
    public void enterMainMenu() {
        System.out.println("-------------------------------------开发团队调度软件--------------------------------------");
        System.out.println("");
        System.out.println("ID    姓名    年龄    工资        职位        状态    奖金       股票    领用设备");
        NameListService nameListService=new NameListService();
        listAllEmployees();

        System.out.println("----------------------------------------------------------------------------------------------");
        System.out.println("");
        System.out.print("1-团队列表 2-添加团队成员 3-删除团队成员 4-退出 请选择(1-4)：");
        switch(readMenuSelection()){
            case 1:
                getTeamN();
                readReturn();
                enterMainMenu();
            case 2:
                addMemberN();
                readReturn();
                enterMainMenu();
            case 3:
                deleteMember();
                readReturn();
                enterMainMenu();
            case 4:
                System.exit(0);
        }


    }

    private void listAllEmployees() {
        listSvc.getAllEmployees();
    }

    private void getTeamN() {
        Programmer[] team=teamSvc.getTeam();
        for (int i = 0; i < team.length-1; i++) {
            System.out.println("-------------------------------------------团队成员列表------------------------------");
            System.out.println("");
            System.out.println(team[i].toString());
            System.out.println("");
            System.out.println("-----------------------------------------------------------------------------------");

        }
    }

    private void addMemberN() {
        System.out.println("-------------添加成员-------------------------------");
        System.out.println();
        System.out.println("请输入要添加的员工 ID：");
        Scanner sc=new Scanner(System.in);
        int id = sc.nextInt();
        System.out.println();
        teamSvc.addMember(listSvc.getEmployee(id));
        TeamException teamException=new TeamException("添加成功");
    }

    private void deleteMember() {
        System.out.println("-------------删除成员-------------------------------");
        System.out.println("");
        System.out.println("请输入要删除的员工 ID：");
        Scanner sc=new Scanner(System.in);
        int id = sc.nextInt();
        System.out.println("确认是否删除(Y/N)：");
        readConfirmSelection();
        teamSvc.removeMember(id);
        TeamException teamException=new TeamException("删除成功");
    }

    public static void main(String[] args) {
        TeamView teamView = new TeamView();
        teamView.enterMainMenu();
    }
}
